package edu.umassd.visual.util;

import java.awt.geom.Rectangle2D;

public class Rectangle extends Rectangle2D.Double
{
	private static final long serialVersionUID = 2543642201331399415L;

	public Rectangle(Rectangle2D copy)
	{
		setRect(copy);
	}

	public Rectangle(double x, double y, double width, double height)
	{
		setRect(x, y, width, height);
	}

	public Rectangle(double width, double height)
	{
		setRect(0.0, 0.0, width, height);
	}

	/**
	 * Copied from {@link java.awt.Rectangle#grow(int, int)}, and adjusted to
	 * work with a double rectangle.
	 * 
	 * @param h
	 *            the horizontal expansion
	 * @param v
	 *            the vertical expansion
	 */
	public void grow(double h, double v)
	{
		double x0 = this.getX();
		double y0 = this.getY();
		double x1 = this.getWidth();
		double y1 = this.getHeight();

		x1 += x0;
		y1 += y0;

		x0 -= h;
		y0 -= v;
		x1 += h;
		y1 += v;

		x1 -= x0;
		y1 -= y0;

		setRect(x0, y0, x1, y1);
	}

	/**
	 * Moves the rectangle by the provided adjustments.
	 * 
	 * @param xAdjust
	 *            - the change in the x direction.
	 * @param yAdjust
	 *            - the change in the y direction.
	 */
	public void setLocation(double xAdjust, double yAdjust)
	{
		double newX = getX() + xAdjust;
		double newY = getY() + yAdjust;

		setRect(newX, newY, getWidth(), getHeight());
	}
}
